function secondsToString(seconds) {
    var numdays = Math.floor(seconds / 86400);
    var numhours = Math.floor((seconds % 86400) / 3600);
    var numminutes = Math.floor(((seconds % 86400) % 3600) / 60);
    var numseconds = ((seconds % 86400) % 3600) % 60;

    return numdays + "d " + numhours + "h " + numminutes + "m " + numseconds + "s";
}

function productionCountdown() {
    time["building"] = time["building"] > 0 ? time["building"]-1 : 0;
    time["research"] = time["research"] > 0 ? time["research"]-1 : 0;
    time["shipyard"] = time["shipyard"] > 0 ? time["shipyard"]-1 : 0;
    $("#time_"+"building").text(secondsToString(time["building"]));
    $("#time_"+"research").text(secondsToString(time["research"]));
    $("#time_"+"shipyard").text(secondsToString(time["shipyard"]));
}

$(document).ready(function (){
    setInterval(productionCountdown,1000);
});